{% extends 'base.html' %}

{% block page-content %}
    <div class="container">
        <div class="container-fluid" style="margin-top: 10px">
            <div class="row" v-for="(datatemp,index) in dataList" style="margin-top: 20px">
                <div class="col-md-3 col-sm-4" v-for="(item,index) in datatemp.data">
                    <div class="product-grid mydiv">
                        <div class="product-image">
                            <a href="#" @click="readInfo(item)">
                                <img class="pic-1" :src="item.CoverChart" style="height: 170px">
                            </a>
                        </div>
                        <div class="product-content">
                            <div class="row-show"><h3 class="title"><a href="#">[[item.Title]]</a></h3>
                                <div class="price" style="color: red;margin-left: 10px"><i class="fa fa-download"></i>[[item.HotValue]]</div>
                            </div>
                            <div class="row-show" style="font-size: 12pt;margin-top: 5px">
                                <div>作者：[[item.UserName]]</div>
                            </div>
                            <div class="row-show" style="font-size: 12pt;margin-top: 5px">
                                <p>简介：[[item.Abstract]]</p>
                            </div>
                        </div>
                        <ul class="social">
                            <li><a href="#" data-tip="查看详情" @click="readInfo(item)"><i class="fa fa-info"></i></a>
                            </li>
                            <li><a href="#" data-tip="下载" @click="downLoadData(item)"><i class="fa fa-download"></i></a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div style="margin-top: 30px">
            <pageination :total="model.total" :size="model.size" :page="model.page" :changge="pageFn"></pageination>
        </div>
    </div>
{% endblock %}


{% block page-scripts %}

    <script src="/static/js/pageination.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            // 分割符: 修改vue中显示数据的语法, 防止与django冲突
            delimiters: ['[[', ']]'],
            components: {},
            data: {
                dataList: [], //
                searchKey: "", //名称检索
                showMessage: "",
                model: {
                    total: 1,//总页数
                    size: 8,//每页显示条目个数不传默认10
                    page: 1,//当前页码
                },

            },
            created() {
                this.getDataList();//页面加载完成后 默认请求
            },
            methods: {
                async getDataList() {
                    //获取交流主记录
                    let data = {
                        curPage: this.model.page,
                        pageSize: this.model.size,
                        searchKey: this.searchKey,
                    };
                    //axios 请求后端主页数据接口
                    let res = await axiospost("{% url 'index' %}", data);
                    console.log(res);
                    if (res.code == 200) {
                        this.dataList = [];
                        let tempList = [];
                        res.data.items.map((item, index) => {
                            index = index + 1;
                            tempList.push(item)
                            if (index % 4 == 0) {
                                this.dataList.push({group: index, data: tempList});
                                tempList = [];
                            }
                        });
                        if (tempList.length > 0) {
                            this.dataList.push({group: 99, data: tempList})
                        }
                        this.model.total = res.data.sumNum;
                    }
                },
                //页码切换执行方法
                pageFn(val) {
                    this.model.page = val;
                    this.getDataList();
                },
                //检索时重置当前页码为1
                searchData() {
                    this.model.page = 1;
                    this.getDataList();
                },
                readInfo(item)
                {
                      window.location.href = "{% url 'data_detail' %}?id=" + item.ID ;
                },
                 async downLoadData(item) {
                    let data = {id: item.ID};
                    let res = await axiosget("{% url 'download_data' %}", data);
                    console.log(res);
                    if (res.code == 200) {
                        //打开新页面下载
                        window.location.href = res.data.url;
                        //window.open(res.data.url);
                    } else {
                        //跳转充值页面
                        window.location.href = "{% url 'pay_money' %}";
                    }
                },


            },
            computed: {
                // 计算属性的 getter
            }
        });
    </script>

{% endblock %}
{% block page-styles %}
    <style>
        form {
            font-size: 12pt;
        }

        .product-grid {
            font-family: 'Open Sans', sans-serif;
            text-align: center;
            overflow: hidden;
            position: relative;
            transition: all 0.5s ease 0s;
        }

        .product-grid:hover {
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        }

        .product-grid .product-image {
            overflow: hidden;
        }

        .product-grid .product-image a {
            display: block;
        }

        .product-grid .product-image img {
            width: 100%;
            height: auto;
            transition: all 0.5s ease 0s;
        }

        .product-grid:hover .product-image img {
            transform: scale(1.1);
        }

        .product-grid .product-content {
            padding: 12px 12px 15px 12px;
            transition: all 0.5s ease 0s;
        }

        .product-grid:hover .product-content {
            opacity: 0;
        }

        .product-grid .title {
            font-size: 20px;
            font-weight: 600;
            text-transform: capitalize;
            margin: 0 0 10px;
            transition: all 0.3s ease 0s;
        }

        .product-grid .title a {
            color: #000;
        }

        .product-grid .title a:hover {
            color: #2e86de;
        }

        .product-grid .price {
            font-size: 18px;
            font-weight: 600;
            color: #2e86de;
        }

        .product-grid .price span {
            color: #999;
            font-size: 15px;
            font-weight: 400;
            text-decoration: line-through;
            margin-left: 7px;
            display: inline-block;
        }

        .product-grid .social {
            background-color: #fff;
            width: 100%;
            padding: 0;
            margin: 0;
            list-style: none;
            opacity: 0;
            transform: translateX(-50%);
            position: absolute;
            bottom: -50%;
            left: 50%;
            z-index: 1;
            transition: all 0.5s ease 0s;
        }

        .product-grid:hover .social {
            opacity: 1;
            bottom: 20px;
        }

        .product-grid .social li {
            display: inline-block;
        }

        .product-grid .social li a {
            color: #909090;
            font-size: 16px;
            line-height: 45px;
            text-align: center;
            height: 45px;
            width: 45px;
            margin: 0 7px;
            border: 1px solid #909090;
            border-radius: 50px;
            display: block;
            position: relative;
            transition: all 0.3s ease-in-out;
        }

        .product-grid .social li a:hover {
            color: #fff;
            background-color: #2e86de;
            width: 80px;
        }

        .product-grid .social li a:before,
        .product-grid .social li a:after {
            content: attr(data-tip);
            color: #fff;
            background-color: #2e86de;
            font-size: 12px;
            letter-spacing: 1px;
            line-height: 20px;
            padding: 1px 5px;
            border-radius: 5px;
            white-space: nowrap;
            opacity: 0;
            transform: translateX(-50%);
            position: absolute;
            left: 50%;
            top: -30px;
        }

        .product-grid .social li a:after {
            content: '';
            height: 15px;
            width: 15px;
            border-radius: 0;
            transform: translateX(-50%) rotate(45deg);
            top: -20px;
            z-index: -1;
        }

        .product-grid .social li a:hover:before,
        .product-grid .social li a:hover:after {
            opacity: 1;
        }

        @media only screen and (max-width: 990px) {
            .product-grid {
                margin-bottom: 30px;
            }
        }

        .row-show {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;
        }

        .row-leftshow {
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .mydiv {

            border: #909090 1px solid;

            background: #fff;

            color: #333;

            filter: progid:DXImageTransform.Microsoft.Shadow(color=#909090, direction=120, strength=4);

            -moz-box-shadow: 2px 2px 10px #909090;

            -webkit-box-shadow: 2px 2px 10px #909090;

            box-shadow: 2px 2px 10px #909090;

            height: 300px;
        }

        .pageination_align {
            text-align: center
        }

        .pageination {
            color: #48576a;
            font-size: 12px;
            display: inline-block;
            user-select: none;
        }

        .pagination_page {
            padding: 0 4px;
            border: 1px solid #d1dbe5;
            border-right: 0;
            background: #fff;
            font-size: 20px;
            min-width: 35px;
            height: 28px;
            line-height: 28px;
            cursor: pointer;
            box-sizing: border-box;
            text-align: center;
            float: left;
        }

        .pagination_page_right {
            border-right: 1px solid #d1dbe5;
        }

        .pagination_page:hover {
            color: #20a0ff;
        }

        .disabled {
            color: #e4e4e4 !important;
            background-color: #fff;
            cursor: not-allowed;
        }

        .pagination_page_active {
            border-color: #20a0ff;
            background-color: #20a0ff;
            color: #fff !important;;
            cursor: default;
        }
    </style>
{% endblock %}